<?php
require_once '../config.php';
require_once '../util.php';

connect_db_mute();

$today = date('Y-m-d');

$tweet_author_id = $_POST['tweet_author_id'];
$tweet_id = $_POST['tweet_id'];

if (isset($tweet_author_id) and empty($tweet_id))
    $sql = "select * from retweet_log where tweet_author_id = $tweet_author_id";

else if (isset($tweet_id) and empty($tweet_author_id))
    $sql = "select * from retweet_log where tweet_id = $tweet_id";

$ret = sql_or_die($sql);

$logs = array();
$check_repeat_array = array();

while ($row = mysql_fetch_assoc($ret)) {
    if (empty($tweet_id)) {
        $check_repeat_item = sprintf('%s%s', $row['tweet_id'], $row['used_follwoers_ammount']);
        if (count($check_repeat_array) == 0)
            $check_repeat_array[] = $check_repeat_item;

        else if (in_array($check_repeat_item, $check_repeat_array))
            continue;
        
        else
            $check_repeat_array[] = $check_repeat_item;
    }

    $sql = sprintf('select local_id, screen_name from user_statistic where user_id like %s and collect_date like "%s"', $row['user_id'], $today);
    $user_info_ret = sql_or_die($sql);
    $user_info = mysql_fetch_assoc($user_info_ret);

    $sql = 'select value from core_config where name = "url_prefix"';
    $url_prefix_ret = sql_or_die($sql);
    $url_prefix = mysql_fetch_assoc($url_prefix_ret);

    $row['screen_name'] = $user_info['screen_name'];
    $row['local_id'] = $user_info['local_id'];
    $row['url_prefix'] = $url_prefix['value'];
    $logs[] = $row;
    //array_push($logs, $row);
}

echo json_encode($logs);

mysql_close();
?>
